module TasksHelper

	def current_week
	  tab = []
	  days_of_the_week.each do |day|
		tab << formated_date(day)
	  end
	  tab
	end

	def days_of_the_week
	  day = @startdate.at_beginning_of_week
	  i= 0
	  tab = []
	  until ( i >= 7 )
		tab << day
		day = day.next
		i += 1
	  end
	  tab
	end

	def format_tasks
		days = days_of_the_week
		calendar = []
		(0..24).each do |hour|
			htasks = []
			days.each do |day|
				dtasks = []
				@tasks.each do |task|
					if ( task.date.day == day.day && task.date.hour == hour )
						dtasks << task
					end
				end
				htasks << dtasks
			end
			calendar << htasks
		end
		calendar
	end
	
	private
	def formated_date(day)
		french_week = %w(Dimanche Lundi Mardi Mercredi Jeudi Vendredi Samedi)
		"#{french_week[day.wday]} #{day.mday}/#{day.month}"
	end
end
